package com.example.springboot.service;

import com.example.springboot.entity.Supplier;
import com.example.springboot.entity.User;
import com.example.springboot.mapper.SupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;

    public int save(Supplier supplier){
        if(supplier.getId()==null){
            return supplierMapper.insert(supplier);
        }else{
            return supplierMapper.update(supplier);
        }
    }

    //批量增加
    public Integer saveBatch(List<Supplier> suppliers){
        Integer num = 0;
        for(int i=0; i<suppliers.size();i++){
            Supplier supplier = suppliers.get(i);
            if(supplier.getId()==null){
                num += supplierMapper.insert(supplier);
            }else{
                num += supplierMapper.update(supplier);
            }
        }
        return num;
    }
}
